package com.global.emc.spring.exception.handler.modelandview;

import org.springframework.web.servlet.ModelAndView;

import com.global.emc.core.exception.IEMCException;
import com.global.emc.spring.exception.handler.SpringModelAndViewEMCExceptionHandler;

/**   
 *  
 * @Description:  [根据错误码、默认视图、异常对象设置ModelAndView]   
 * @Author:       [Joly_Huang]   
 * @CreateDate:   [2014年2月21日 上午9:56:04]   
 * @UpdateUser:   [Joly_Huang]   
 * @UpdateDate:   [2014年2月21日 上午9:56:04]   
 * @UpdateRemark: [说明本次修改内容]  
 * @Version:      [v1.0] 
 *    
 */
public class SimpleModelAndViewEMCExceptionHandler implements SpringModelAndViewEMCExceptionHandler{
	private String defaultErrorView="DefaultExceptionView";
	private String exceptionAttribute="_exception";
	
	public String getDefaultErrorView() {
		return defaultErrorView;
	}

	public void setDefaultErrorView(String defaultErrorView) {
		this.defaultErrorView = defaultErrorView;
	}

	public String getExceptionAttribute() {
		return exceptionAttribute;
	}

	public void setExceptionAttribute(String exceptionAttribute) {
		this.exceptionAttribute = exceptionAttribute;
	}

	@Override
	public boolean supports(IEMCException emcException) {
		return null != emcException;
	}

	@Override
	public void handlerModelAndView(ModelAndView modelAndView, IEMCException emcException) {
		handlerView(modelAndView, emcException);
		handlerModel(modelAndView, emcException);
	}
	
	protected void handlerView(ModelAndView modelAndView, IEMCException emcException) {
		modelAndView.setViewName(defaultErrorView);
	}
	
	protected void handlerModel(ModelAndView modelAndView, IEMCException emcException) {
		if (this.exceptionAttribute != null) {
			modelAndView.addObject(this.exceptionAttribute, emcException);
		}
	}

}
